<?php

namespace app\api\model;


use traits\model\SoftDelete;

class Dish extends BaseModel
{
    protected $resultSetType = 'collection';
    // 关联商品图片一对多
    public function dishImg()
    {
        return $this->hasMany('Detail', 'dish_id', 'id');
    }

    // 静态查询
    public static function getDishByCate($dish_cate)
    {
        $dish = self::where('dish_cate', '=', $dish_cate)->with('dishImg')->order('create_time', 'desc')->select();

        return $dish;
    }

    // 读取器调用基类方法处理图片url地址
    public function getDishImagesAttr($value)
    {
        return $this->prefixImages($value);
    }
}
